package  com.kdgc.power.base.controller;

import com.kdgc.power.base.entity.BaseMusic;
import com.kdgc.power.base.service.BaseMusicService;
import com.kdgc.power.fw.bean.JsonMsg;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import java.util.Map;

@Controller
@RequestMapping("BaseMusic")
public class BaseMusicController {
    @Autowired
    private BaseMusicService baseMusicService;

    @ResponseBody
    @RequestMapping("page")
    public Object getPage(HttpServletRequest request, int page, int rows) {
        String musicName = request.getParameter("musicName");
        return  baseMusicService.searchPage( page, rows, musicName);
    }

    @ResponseBody
    @RequestMapping("findById")
    public Map<String,Object> findById(Integer id) {
        return  baseMusicService.getMapEntity(id);
    }

    @ResponseBody
    @RequestMapping("save")
    public JsonMsg save(BaseMusic entity) {
        boolean success = baseMusicService.saveOrUpdate(entity);
        return new JsonMsg(success);
    }

    @ResponseBody
    @RequestMapping("deleteById")
    public JsonMsg deleteById(Integer id) {
        int rows = baseMusicService.removeById(id);
        return new JsonMsg(rows == 1);
    }
}